#include "human.h"
#include "humanManager.h"

bool Human::setLover(uint8 id)
{
	Human *pHuman = HumanManager::getInstance()->getHumanByID(id);
	if(pHuman)
	{
		this->lover = id;
		return true;
	}
	else return false;
}
void Human::talk(const uint8 saying, uint32 id)
{
	Human *pHuman = HumanManager::getInstance()->getHumanByID(id);
	if(pHuman)
	{
		std::string talk;
		if(Talking::getInstance()->getTalkByID(saying, talk))
		{
			std::cout << this->name << " say to " << pHuman->name << ": " << talk << std::endl;
			pHuman->getTalk(saying, this->id);
		}
	}
}
void Human::getTalk(const uint8 saying, uint32 id)
{
	Human *pHuman = HumanManager::getInstance()->getHumanByID(id);
	if(pHuman)
	{
		uint8 talkBack = Talking::getInstance()->getNextTalkByID(saying);
		this->talk(talkBack, id);
	}
}

Human* Human::birth(const std::string &name)
{
	if(this->sex == SEX_FEMALE && this->married == true)
	{
		Human *pHuman = new Human(ID_Alloc::getInstance()->alloc(), name, randBetween(0, 1) == 0?SEX_MALE:SEX_FEMALE);
		if(pHuman)
		{
			pHuman->setEmotion(EMOTION_CRY);
			HumanManager::getInstance()->pushHuman(pHuman);
			return pHuman;
		}
	}
	return NULL;
}
